
package com.ukao.pad.presenter;

import android.content.Context;
import com.ukao.pad.base.BasePresenter;
import com.ukao.pad.bean.AddressList;
import com.ukao.pad.bean.StringBean;
import com.ukao.pad.bean.serviceTimeBean;
import com.ukao.pad.consts.Constant;
import com.ukao.pad.consts.SaveParamets;
import com.ukao.pad.retrofit.ApiCallback;
import com.ukao.pad.view.PlaceoOrderView;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by ukaodev on 2017/6/28.
 */

public class PlaceOrderPresenter extends BasePresenter<PlaceoOrderView> {

    public PlaceOrderPresenter(PlaceoOrderView view) {
        attachView(view);
    }


    public void serviceTimeData(Context  mContext) {
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("accessToken", SaveParamets.getToken(mContext));
        mHashMap.put("type","1");
        addSubscription(apiStores.serviceTime(Constant.createParameter(mHashMap)),
                new ApiCallback<serviceTimeBean>() {
                    @Override
                    public void onSuccess(serviceTimeBean model) {

                        if (model.getHttpCode()==200){
                            mvpView.serviceTimeSucceed(model.getData().getList());
                        }else{

                            mvpView.loadFail(model.getMsg());
                        }

                    }

                    @Override
                    public void onNoNewWork() {

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }

    /**
     *获取用户地址
     */

    public void getAddressRequest(Context mContext,String userId) {
       mvpView.showLoading();
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("userId", userId);
        mHashMap.put("accessToken", SaveParamets.getToken(mContext));
        addSubscription(apiStores.userAddress(Constant.createParameter(mHashMap)),
                new ApiCallback<AddressList>() {
                    @Override
                    public void onSuccess(AddressList model) {

                        if (model.getHttpCode() == 200) {
                            ArrayList<AddressList>         mAddressList= (ArrayList<AddressList>) model.getData();
                            mvpView.addressDataSucceed(mAddressList);

                        }else{
                        mvpView.loadFail(model.getMsg());
                    }
                }

                    @Override
                    public void onNoNewWork() {

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }




    /*下单*/
    public void orderInfoAddRequest(HashMap mHashMap) {
     mvpView.showLoading();
        addSubscription(apiStores.orderInfoAdd(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {
                        if (model.getHttpCode() == 200) {
                            mvpView.orderInfoAddSucceed(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }
                    }
                    @Override
                    public void onNoNewWork() {

                    }
                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }





}
